<?php
class Google_Subcalendars extends Ot_Db_Table 
{
    /**
     * Database table name
     *
     * @var string
     */
    public $_name = 'google_subcalendars';

    /**
     * Primary key for the database
     *
     * @var string
     */
    protected $_primary = 'subCalendarId';

	public function checkIdentifierExists($identifier)
    {
        $dba = $this->getAdapter();
        $where = $dba->quoteInto('identifier = ?', $identifier);
        $result = $this->fetchAll($where); 
        return $result->count();
    }
	
    
    public function form(array $default = array())
    {
    	$form = new Zend_Form();
    	$form->setAction('')
             ->setMethod('post')
             ->setAttrib('id', 'typeForm')
             ->setDecorators(array(
                 'FormElements',
                 array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')),
                 'Form',
             ));
            	         
        $identifier = $form->createElement('text', 'identifier', array('label' => 'Unique Identifier for this sub-calendar:'));
        $identifier->setRequired(true)
             ->addFilter('StringTrim')
             ->addFilter('StripTags')
             ->addFilter('alnum')
             ->setAttrib('maxlength', '255')
             ->setValue((isset($default['identifier'])) ? $default['identifier'] : '');
        
        $gmailSubCalendarId = $form->createElement('text', 'gmailSubCalendarId', array('label' => 'Gmail Sub-Calendar ID:'));
        $gmailSubCalendarId->setRequired(true)
             ->addFilter('StringTrim')
             ->addFilter('StripTags')
             ->setAttrib('maxlength', '255')
             ->setAttrib('size', '75')
             ->setValue((isset($default['gmailSubCalendarId'])) ? $default['gmailSubCalendarId'] : '');
       	
        $submit = $form->createElement('submit', 'saveButton', array('label' => 'Save Sub-Calendar'));
        $submit->setDecorators(array(
                   array('ViewHelper', array('helper' => 'formSubmit'))
                 ));
        
        $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel'));
        $cancel->setAttrib('id', 'cancel');
        $cancel->setDecorators(array(
                   array('ViewHelper', array('helper' => 'formButton'))
                ));        
                            
        $form->addElements(array($identifier, $gmailSubCalendarId))
             ->setElementDecorators(array(
                     'ViewHelper',
                     'Errors',      
                     array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), 
                     array('Label', array('tag' => 'span')),      
             ))
             ->addElements(array($submit, $cancel));
             
        return $form;
    }
    
	public function removeSubCalendarForm(array $default = array())
    {
    	$form = new Zend_Form();
    	$form->setAction('')
             ->setMethod('post')
             ->setAttrib('id', 'typeForm')
             ->setDecorators(array(
                 'FormElements',
                 array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')),
                 'Form',
             ));
       	
        $submit = $form->createElement('submit', 'saveButton', array('label' => 'Remove Sub-calendar'));
        $submit->setDecorators(array(
                   array('ViewHelper', array('helper' => 'formSubmit'))
                 ));
        
        $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel'));
        $cancel->setAttrib('id', 'cancel');
        $cancel->setDecorators(array(
                   array('ViewHelper', array('helper' => 'formButton'))
                ));        
                            
        $form->addElements(array($submit, $cancel));
             
        return $form;
    }




}